<!--
   face.html
   
   Copyright 2013 dnclive <dnclive@ubunlive3>
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   MA 02110-1301, USA.
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<title>Тест для ОНТИКО</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.21" />
	
	<link rel="stylesheet" type="text/css" href="css.css">
	
	<!--script data-main="/" src="requirejs/require.js"></script!-->
	
	<script>
		var dojoConfig = 
		{
			async:true,
			isDebug:false,
			cacheBust:false,
			parseOnLoad: true,
			locale:'ru',
			waitSeconds:5,
			paths:
			{
				"tlib":"../tlib",
				"res":"../../../../../../res",
				"tpl":"",
			},
		};
	</script>
	
	<script src="res/josi_lib/js/release/dojo/dojo/dojo.js"></script>
	<!--script src="res/josi_lib/js/dev/dojo/dojo/dojo.js"></script-->
	
	<script>
		var mod_1;
		var mod_2;
		require
		(
			[	
				//"XMLHttpRequest.js",
				"dojo/_base/xhr",
				"dojo/dom-class",
				"dojo/query",
				"dojo/on",
				"dojo/_base/json",
				"tlib/tuti",
			],
			function
			(
				t_xhr,
				t_class,
				t_query,
				t_on,
				t_json,
				t_uti
			)
			{
				mod_1=
				{
					
					args:
					{
						filling_students:false,
						filling_news:false,
						vkcom:
						{
							access_token:"",
						}
					},
					
					//наполнение базы
					f_news_fill:function(args)
					{
						var self=this;
						var args=args||{};
						var limit=args.limit||[];
						var rss_url=t_query(".id_rss_url")[0].value;
						
						var is_recall=args.is_recall;
						var repeate=args.repeate;
						
						var bnt_node=t_query(".btn_fill_news_2")[0];
						var log_node=t_query(".log_1")[0];
						var waiter_node=t_query(".waiter_div")[0];
						
						t_class.remove(waiter_node,"hidden");
						
						//console.log("123");
						
						if (repeate)
						{
							if (!is_recall&&self.args.filling_news)
							{
								self.args.filling_news=false;
								bnt_node.innerHTML="Запустить";
								
								t_class.add(waiter_node,"hidden");
								
								return;
							}
							
							if(!self.args.filling_news)
							{
								self.args.filling_news=true;
								bnt_node.innerHTML="Остановить";
							}
						}
						
						//return;
						
						t_xhr("GET",
						{
							url:"f.php?f="+args.f+"&rss_url="+rss_url,
							handleAs:"text",
							load: function(data)
							{
								
								console.log(t_query(".log_1"));
								//на случай если ошибка
								try
								{
									resp=t_json.fromJson(data);
									console.log(resp);
									t_query(".log_1")[0].innerHTML+=resp.log;
									
									
									
								}
								catch(e)
								{
									t_query(".log_1")[0].innerHTML+=data;
									//console.log(data);
									//resp=args.resp_data;
								}

								//ессли процесс заполнения базы не остановили
								if (self.args.filling_news&&repeate)
								{
									//рекурсивно вызываем себя инкрементируя
									//диапазон запроса
									setTimout(self.f_news_fill(
									{
										f:args.f,
										is_recall:true,
										repeate:true,
									}), 3000);
								}
								else
								{
									t_class.add(waiter_node,"hidden");
								}
							},
							error:function(err)
							{
								
							}
						});
						
					},
					
					//получение последних новостей
					f_get_news:function(args)
					{
						var self=this;
						var args=args||{};
						var limit=args.limit||[];
						var count=t_query(".id_count_news")[0].value;
						
						//console.log("123");
						
						
						
						//return;
						
						t_xhr("GET",
						{
							url:"f.php?f="+args.f+"&count="+count,
							handleAs:"text",
							load: function(data)
							{
								
								console.log(t_query(".log_3"));
								//на случай если ошибка
								try
								{
									resp=t_json.fromJson(data);
									console.log(resp);
									t_query(".log_3")[0].innerHTML+=resp.log;
									
									t_query(".news_box")[0].innerHTML="";
									
									var news_item=""
									var i=0;
									console.log(resp.res.length);
									while(i<resp.res.length)
									{
										news_item='<div style="overflow: hidden;margin-top: 10px;background: #CFC;">'+
														'<div class="left">'+resp.res[i].title+'</div>'+
														'<div class="right">'+resp.res[i].pubdate+'</div>'+
													'</div>'+
													'<div>'+resp.res[i].description+'</div>';
										t_query(".news_box")[0].innerHTML+=news_item;
										i++;
									}
									
								}
								catch(e)
								{
									t_query(".log_3")[0].innerHTML+=data;
									//console.log(data);
									//resp=args.resp_data;
								}

								
							},
							error:function(err)
							{
								
							}
						});
						
					},
				
					
				
				};
			}
		);
	
	</script>
	
</head>

<body>
	<div class="main">
		<div class="content_left">
			<div><h2>Наполнение базы</h2></div>
			<div>
				<div class="left" style="width: 200px;">rss_url</div>
				<input class="left id_rss_url" type="text" value="http://rss.cnn.com/rss/edition_americas.rss"/>
			</div>
			<div style="width:100%;overflow:hidden">
				<div class="btn left btn_fill_news_1" onClick="mod_1.f_news_fill({f:'f_news_fill'})">Залить в news</div>
				<div class="btn left btn_fill_news_2" onClick="mod_1.f_news_fill({f:'f_news_fill_2',repeate:true})">Залить в tab_news</div>
			</div>
			<textarea class="log_1" style="min-width:100%;min-height:300px">
			
			</textarea>
		</div>
		<div class="content_center" style="padding:10px">
			
		</div>
		<div class="content_right">
			<div><h2>Получение новостей из базы</h2></div>
			<div style="overflow:hidden">
				<div class="left" style="width: 200px;">Count</div>
				<input class="left id_count_news" type="text" value="3"/>
			</div>
			<div class="left" style="overflow:hidden">
				<h3>news</h3>
				<div class="btn btn_get_news" onClick="mod_1.f_get_news({f:'f_news_1'})">get by limit</div>
				<div class="btn btn_get_news" onClick="mod_1.f_get_news({f:'f_news_2'})">get by desc</div>
				<div class="btn btn_get_news" onClick="mod_1.f_get_news({f:'f_news_2'})">get by >id</div>
			</div>
			<div class="left" style="overflow:hidden">
				<h3>tab_news</h3>
				<div class="btn btn_get_news" onClick="mod_1.f_get_news({f:'f_tab_news_1'})">get by limit</div>
				<div class="btn btn_get_news" onClick="mod_1.f_get_news({f:'f_tab_news_2'})">get by desc</div>
				<div class="btn btn_get_news" onClick="mod_1.f_get_news({f:'f_tab_news_3'})">get by >id</div>
			</div>
			<textarea class="log_3" style="min-width:100%;min-height:300px">
			
			</textarea>
			<div class="news_box" style="width:100%">
				<div style="overflow: hidden;margin-top: 10px;background: #CFC;">
					<div class="left">Заголовок</div>
					<div class="right">Дата</div>
				</div>
				<div>Описание</div>
			</div>
		</div>
	</div>
	
	<div class="waiter_div hidden">
		<div style="overflow: hidden;
					margin: 0 auto;
					width: 140px;
					text-align: center;">
			<div style="float:left">Загрузка</div>
			<img src="res/tpl/waiter/26.gif" style="float: left;
												height: 30px;
												padding: 0px 0px 0px 5px;"/>
		</div>
	</div>
</body>

</html>
